package com.hodge.core.enums;

import com.hodge.core.exception.MyException;
import com.hodge.core.result.Result;

/**
 * 返回状态码
 *
 * @author haojun
 * @since 2020/3/18 18:44
 */
public enum ResultCode {
    SUCCESS("成功"),
    FAILURE("失败"),

    SERVER_ERROR("服务器出错"),
    ACCESS_DENIED("无权访问"),

    NOT_LOGIN("未登录"),
    LOGIN_FALIURE("登录失败"),
    EXIST_ACCOUNT("账号被占用"),
    LOCKED_ACCOUNT("账号被冻结"),
    UNKNOWN_ACCOUNT("账号不存在"),
    ERROR_PASSWORD("密码不正确"),

    DATA_VERIFY_ERROR("数据校验失败"),

    NO_HANDLER_FOUND("接口不存在"),
    MISSING_REQUEST_PARAMETERS("缺少请求参数"),
    REQUEST_METHOD_NOT_SUPPORTED("错误的请求方法"),
    ;

    private final String msg;

    ResultCode(String msg) {
        this.msg = msg;
    }

    public String getMsg() {
        return msg;
    }

    public Result toResult() {
        return Result.code(this);
    }

    public Result toResult(String message) {
        return Result.code(this).setMessage(message);
    }

    public MyException toException() {
        return new MyException(this.toResult());
    }
}
